﻿
using Codemonk.Pease.Common;
using System.Web.Script.Serialization;
namespace Codemonk.Pease.Server.Serialization
{
    public class JsonSerializater : ISerializater<string>
    {
        private static JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
        public string Serialize(object obj)
        {
            try
            {
                return jsSerializer.Serialize(obj);
            }
            catch
            {
                return string.Empty;
            }
        }

        public B Deserialize<B>(string data)
        {
            try
            {
                return jsSerializer.Deserialize<B>(data);
            }
            catch
            {
                return default(B);
            }
        }
    }
}
